package com.wpfap.kfzapp;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;

public class UebersichtActivity<T> extends Activity {
    private ImageView gfxButton;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uebersicht);
        final List valueList = new ArrayList<String>();

        File dir = new File(Environment.getExternalStorageDirectory()+"/wpfap/");
        String[] fileList = dir.list(new FilenameFilter() {
            @SuppressWarnings("unchecked")
			public boolean accept(File d, String name) {
            	if (!name.endsWith(".jpg")) valueList.add(name);
            	return true;
            }
        });


        this.gfxButton = (ImageView)this.findViewById(R.id.app_logo);
        ((ImageView) this.gfxButton).setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent gfx = new Intent(UebersichtActivity.this, GfxActivity.class);
                startActivity(gfx);
            }
          });
        
        ListAdapter adapter = new ArrayAdapter<T>(getApplicationContext(), android.R.layout.simple_list_item_1, valueList);
        final ListView lv = (ListView)findViewById(R.id.listView1);

        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener()
        {
        public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3)
        {
        Intent intent = new Intent(UebersichtActivity.this, EigenschaftActivity.class);

        intent.putExtra("Liste", (String)lv.getItemAtPosition(arg2));
        System.out.println(lv.getItemAtPosition(arg2));

        
        startActivity(intent);
        }
        });
    }
}